home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SNIP0492.ARJ / KILLFF.C < prev    next >
C/C++ Source or Header  |  1991-12-23  |  4KB  |  90 lines

  1. /*
  2. ** This program was written to strip out all the Form Feeds in text
  3. ** files. I hate it when people waste my printer paper! I also like
  4. ** to post News Letters for my Users on my BBS, and imbedded Form
  5. ** Feeds screw things up bad when trying to view the News Letters
  6. ** (like FIDONEWS!) Hope you like it!
  7. **
  8. ** KILL FORM FEEDS v1.1 by Jerry Gore (Public domain?)
  9. ** Version 1.2 by Erik VanRiper on 12/22/91 Public Domain!
  10. **
  11. ** This is basically a complete re-write.
  12. **
  13. ** Reads a text file and makes a duplicate with NO Form Feed
  14. ** characters! The duplicates name will default to temp.txt. Form
  15. ** Feed characters are replaced with a space (decimal 32).
  16. **
  17. ** Usage: KILLFF FILE.TXT [TEMP.TXT]
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23.  
  24. main(int argc, char *argv[])
  25. {
  26.    FILE *in, *out;              /* input and output files        */
  27.    char name[80],               /* name of file to be fixed      */
  28.         temp[80] = "temp.txt",  /* output file name              */
  29.         *buf,                   /* buffer we will use to write   */
  30.         *s;                     /* searching pointer             */
  31.    unsigned int bad,            /* check to see if write ok      */
  32.                 num;            /* number of bytes read          */
  33.  
  34.    printf("\nKILL FORM FEEDS v1.1 by Jerry Gore");
  35.    printf("\nRevised by Erik VanRiper (v1.2)\n\n");
  36.  
  37.    if(argc < 2)                              /* usage info       */
  38.    {
  39.       printf("Usage:\n\tKILLFF input_file [output_file]\n");
  40.       return(0);                             /* return to OS     */
  41.    }
  42.  
  43.    strcpy(name,argv[1]);                     /* input filename   */
  44.    if(argc == 3) strcpy(temp,argv[2]);       /* outfile name     */
  45.  
  46.    if((buf = malloc(32000)) == NULL)   /* malloc a large buffer  */
  47.    {
  48.       printf("\nOut of memory.  :-(\n");
  49.       return(0);                             /* return to OS     */
  50.    }
  51.    if((in = fopen(name,"r")) == NULL)        /* Open in file     */
  52.    {
  53.       printf("\nCan't Open Input File %s!",name);
  54.       free(buf);                             /* free memory      */
  55.       return(0);                             /* return to OS     */
  56.    }
  57.    if((out = fopen(temp,"wt")) == NULL)      /* open out file    */
  58.    {
  59.       printf("\nCan't Open File %s",temp);
  60.       fclose(in);                            /* close in file    */
  61.       free(buf);                             /* free memory      */
  62.       return(0);                             /* return to OS     */
  63.    }
  64.  
  65.    printf("Input file: %s Output file: %s\n",name,temp);
  66.  
  67.    num = fread(buf,sizeof(char *),31999,in); /* read in file     */
  68.    while(num > 0)                         /* while chars to read */
  69.    {
  70.       while((s = strchr(buf, '\x0C')) != NULL) /* look for FF    */
  71.          *s = '\x20';                        /* change to space  */
  72.  
  73.       bad=fwrite(buf,sizeof(char *),num,out); /* write out buf   */
  74.       if(bad != num)                         /* error            */
  75.       {
  76.          printf("\nCan't Write to %s ", temp);
  77.          fclose(in);                         /* close in file    */
  78.          fclose(out);                        /* close out file   */
  79.          free(buf);                          /* free memory      */
  80.          return(0);                          /* return to OS     */
  81.       }
  82.       num = fread(buf,sizeof(char *),31999,in); /* read in more  */
  83.    }
  84.    fclose(in);                               /* close in file    */
  85.    fclose(out);                              /* close out file   */
  86.    free(buf);                                /* free memory      */
  87.    printf("\nDone!");                        /* Finished         */
  88.    return(1);                                /* return to OS     */
  89. }
  90.